/**
 * 
 * 起迪科技 Copyright (c) 2014-2018 QiDi,Inc.All Rights Reserved.
 */

package cn.qidisoft.edu.hzjt.controller.partyJoinApply;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.qidisoft.core.common.log.LoggerAdapter;
import cn.qidisoft.core.common.log.LoggerAdapterFactory;
import cn.qidisoft.edu.hzjt.constants.Constant;
import cn.qidisoft.edu.hzjt.controller.BaseController;
import cn.qidisoft.edu.hzjt.model.UserEmployee;
import cn.qidisoft.edu.hzjt.service.IPartyJoinActivistService;
import cn.qidisoft.edu.hzjt.service.IPartyJoinApplyService;
import cn.qidisoft.edu.hzjt.service.IPartyJoinDevelopmentAttService;
import cn.qidisoft.edu.hzjt.service.IPartyJoinFullService;
import cn.qidisoft.edu.hzjt.service.IPartyJoinReviewService;
import cn.qidisoft.edu.hzjt.service.IPartyJoinTargetService;
import cn.qidisoft.edu.hzjt.utils.LogType;
import cn.qidisoft.edu.hzjt.utils.SpringUtil;
import cn.qidisoft.edu.hzjt.vo.PartyJoinApplyBean;

/**
 * 
 * 
 * @author hhl
 * @version $Id: PartyJoinApplyController.java, v 0.1 2018年12月24日 下午2:42:36 hhl Exp $
 */
@Controller
@RequestMapping(value = "partyJoinApply")
public class PartyJoinApplyController {
  protected static final LoggerAdapter LOGGER =
      LoggerAdapterFactory.getLogger(LogType.HZJT_LOGGER.val);
  @Autowired
  private IPartyJoinApplyService partyJoinApplyService;

  @Autowired
  private IPartyJoinActivistService partyJoinActivistService;

  @Autowired
  private IPartyJoinTargetService partyJoinTargetService;

  @Autowired
  private IPartyJoinReviewService partyJoinReviewService;

  @Autowired
  private IPartyJoinFullService partyJoinFullService;

  @Autowired
  private IPartyJoinDevelopmentAttService partyJoinDevelopmentAttService;

  private static String publicPartyJoinApply(ModelMap model, HttpServletRequest request,
      UserEmployee userEmployee) {
    try {
      PartyJoinApplyBean bean = new PartyJoinApplyBean();
      bean.setUserEmployee(userEmployee);
      IPartyJoinApplyService partyJoinApplyService =
          (IPartyJoinApplyService) SpringUtil.getBean("partyJoinApplyService");
      PartyJoinApplyBean partyJoinApplyBean = partyJoinApplyService.queryPartyJoinApplyStep(bean);
      if (partyJoinApplyBean != null) {
        if (partyJoinApplyBean.getApplyId() == null) {
          partyJoinApplyBean.setStep(1);
          partyJoinApplyBean.setIsHiden(1); // 展现
          model.put("partyJoinApplyBean", partyJoinApplyBean);
          return "partyJoinApply/partyJoinApply";
        } else if (partyJoinApplyBean.getApplyId() != null
            && partyJoinApplyBean.getActivistId() == null) {
          partyJoinApplyBean.setStep(2);
          model.put("partyJoinApplyBean", partyJoinApplyBean);
          return "partyJoinApply/partyJoinApply2";
        } else if (partyJoinApplyBean.getActivistId() != null
            && partyJoinApplyBean.getTargetId() == null) {
          partyJoinApplyBean.setStep(3);
          model.put("partyJoinApplyBean", partyJoinApplyBean);
          return "partyJoinApply/partyJoinApply2";
        } else if (partyJoinApplyBean.getTargetId() != null
            && partyJoinApplyBean.getReviewId() == null) {
          partyJoinApplyBean.setStep(4);
          model.put("partyJoinApplyBean", partyJoinApplyBean);
          return "partyJoinApply/partyJoinApply2";
        } else if (partyJoinApplyBean.getReviewId() != null
            && partyJoinApplyBean.getFullId() == null) {
          partyJoinApplyBean.setStep(5);
          model.put("partyJoinApplyBean", partyJoinApplyBean);
          return "partyJoinApply/partyJoinApply2";
        } else if (partyJoinApplyBean.getFullId() != null) {
          model.put("partyJoinApplyBean", partyJoinApplyBean);
          partyJoinApplyBean.setStep(6);
          return "partyJoinApply/partyJoinApply2";
        } else {
          partyJoinApplyBean.setStep(1);
          partyJoinApplyBean.setIsHiden(0); // 不展现
          model.put("partyJoinApplyBean", partyJoinApplyBean);
          return "partyJoinApply/partyJoinApply";
        }
      } else {
        partyJoinApplyBean = new PartyJoinApplyBean();
        partyJoinApplyBean.setStep(1);
        partyJoinApplyBean.setIsHiden(1); // 展现
        model.put("partyJoinApplyBean", partyJoinApplyBean);
        return "partyJoinApply/partyJoinApply";
      }
    } catch (Exception e) {
      e.printStackTrace();

    }
    return "partyJoinApply/partyJoinApply";

  }

  /**
   * 查看党员入党申请信息
   * 
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/viewPartyJoinApplyInfo")
  public String viewPartyJoinApplyInfo(ModelMap model, HttpServletRequest request) {
    try {
      String sqid = request.getParameter("sqid");
      System.out.println(sqid + "================");
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "查看党员发展信息 viewPartyJoinApplyInfo [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      return "error/error";
    }
    return null;
  }

  /**
   * 查看入党积极分子
   * 
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/viewPartyJoinActivistInfo")
  public String viewPartyJoinActivistInfo(ModelMap model, HttpServletRequest request) {
    try {
      String sqid = request.getParameter("sqid");
      String jjid = request.getParameter("jjid");
      System.out.println(sqid + "================" + jjid);
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          "查看入党积极分子信息 viewPartyJoinActivistInfo [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      return "error/error";
    }
    return null;
  }

  /**
   * 查看预备党员考察
   * 
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/viewPartyJoinReviewInfo")
  public String viewPartyJoinReviewInfo(ModelMap model, HttpServletRequest request) {
    try {
      String sqid = request.getParameter("sqid");
      String dxid = request.getParameter("dxid");
      System.out.println(sqid + "================" + dxid);
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          " 查看预备党员考察信息 viewPartyJoinReviewInfo [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      return "error/error";
    }
    return null;
  }

  /**
   * 查看预备党员考察
   * 
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/viewPartyJoinTargetInfo")
  public String viewPartyJoinTargetInfo(ModelMap model, HttpServletRequest request) {
    try {
      String sqid = request.getParameter("sqid");
      String kcid = request.getParameter("kcid");
      System.out.println(sqid + "================" + kcid);
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          " 查看预备党员考察信息 viewPartyJoinTargetInfo [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      return "error/error";
    }
    return null;
  }

  /**
   * 查看预备党员转正
   * 
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/viewPartyJoinFullInfo")
  public String viewPartyJoinFullInfo(ModelMap model, HttpServletRequest request) {
    try {
      String sqid = request.getParameter("sqid");
      String zzid = request.getParameter("zzid");
      System.out.println(sqid + "================" + zzid);
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error(
          " 查看预备党员转正信息 viewPartyJoinFullInfo [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      return "error/error";
    }
    return null;
  }



  /**
   * 
   * 
   * @param model
   * @param request
   * @return
   */
  @RequestMapping(value = "/index")
  public String index(ModelMap model, HttpServletRequest request) {
    String forward = null;
    try {
      request.setAttribute("msg", BaseController.getParameter("msg"));
      BaseController.removeParameter("msg");
      UserEmployee userEmployee =
          (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
      forward = publicPartyJoinApply(model, request, userEmployee);
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("党员发展信息 index [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(), e.getMessage());
      return "error/error";
    }
    return forward;
  }

  @RequestMapping(value = "/add_partyJoinApply")
  public String add_partyJoinApply(ModelMap model, HttpServletRequest request) {
    UserEmployee userEmployee =
        (UserEmployee) request.getSession().getAttribute(Constant.LOGIN_CONSOLE_USER);
    String forward = publicPartyJoinApply(model, request, userEmployee);
    // return forward;
    return forward;
  }

}
